package com.guigu.community.controller;

import com.guigu.community.pojo.Admins;
import com.guigu.community.pojo.Users;
import com.guigu.community.service.AdminService;
import com.guigu.community.vo.AdminsVo;
import com.guigu.community.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Controller
@RequestMapping("/admin")
@CrossOrigin
public class AdminsController {
    @Autowired
    private AdminService adminService;
    //管理员登录
    @PostMapping(value ="/user",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String login(@RequestBody AdminsVo vo){
        Admins logined = adminService.login(vo);
        if (logined.getPassword().equals(vo.getPassword())){
            return "登录成功，欢迎";
        }
        return "no";
    }


    //注测
    @PostMapping("/register")
    @ResponseBody
    public String register(@RequestBody Admins admins) {
//        admins.setIsBusinesses(0);//默认不是为商户
//        admins.setIsVendor(0);//默认不是为供应商
        admins.setCreatedAt(new Date());
        boolean success = adminService.save(admins);
        if (success) {
            return "注册成功";
        } else {
            return "注册失败";
        }
    }
}
